<?php

namespace App\Remote\XiaoHongShu;

use Closure;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class Remote extends \App\Remote\Remote
{
    /**
     * @inheritDoc
     */
    static function getBaseUri(): string
    {
        // TODO: Implement getBaseUri() method.
        return "http://xhs.pl666.cn";
    }

    /**
     * 小红书返回数据预处理
     *
     * @return Closure
     */
    public static function registerResponseHandle(): Closure
    {
        return function () {
            list($responseHttpCode, $responseContent) = func_get_args();
            if ($responseHttpCode != ResponseAlias::HTTP_OK) {
                throw new \Exception($responseContent);
            }

            if (isJson($responseContent)) {
                $responseArr = jsonToArr($responseContent);
                if ($responseArr["code"] != 1) {
                    throw new \Exception($responseContent);
                }
                return $responseArr;
            }

            throw new \Exception("[ $responseHttpCode ]-[ $responseContent ]");
        }; // TODO: Change the autogenerated stub
    }

    /**
     * 构建公共请求头
     *
     * @return array
     */
    public static function buildBasicHeaders(): array
    {
        return [
            'Content-Type' => "application/json",
        ]; // TODO: Change the autogenerated stub
    }

}
